home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Meshwriter_lib / Library / samples / galaxy.c < prev    next >
C/C++ Source or Header  |  1999-12-03  |  3KB  |  123 lines

  1. /*
  2. **      $VER: galaxy.c 1.00 (27.3.1999)
  3. **
  4. **      Creation date     : 27.3.1999
  5. **
  6. **      Description       :
  7. **         MeshWriter testprogram shape module.
  8. **
  9. **
  10. **      Written by Stephan Bielmann
  11. **
  12. */
  13.  
  14. /*************************** Includes *******************************/
  15.  
  16. #include <stdlib.h>
  17. #include <math.h>
  18.  
  19. #include <meshwriter/meshwriter.h>
  20. #include <pragma/meshwriter_lib.h>
  21.  
  22. /**************************** Defines *******************************/
  23.  
  24. #define PI            3.14159265359
  25.  
  26. /*********************** Type definitions ***************************/
  27.  
  28. /********************** Private functions ***************************/
  29.  
  30. static VOID particleadd(ULONG mesh,ULONG material,TOCLFloat size,TOCLVertex position){
  31.   TOCLVertex x,y,z;
  32.  
  33.   x.x=position.x;
  34.   x.y=position.y-size;
  35.   x.z=position.z;
  36.  
  37.   y.x=position.x+size;
  38.   y.y=position.y+size;
  39.   y.z=position.z;
  40.  
  41.   z.x=position.x-size;
  42.   z.y=position.y+size;
  43.   z.z=position.z;
  44.  
  45.   MWLMeshTriangleAdd(mesh,material,&x,&y,&z);
  46. }
  47.  
  48. static FLOAT random(FLOAT range) {
  49.   return((range * rand () / RAND_MAX)-(range/2));
  50. }
  51.  
  52. /********************** Public functions ****************************/
  53.  
  54. /********************************************************************\
  55. *                                                                    *
  56. * Name         : galaxy                                              *
  57. *                                                                    *
  58. * Description  : Draws a galaxy like shape with the help of the      *
  59. *                    rotation function.                                  *
  60. *                                                                    *
  61. * Arguments    : mesh    IN  : An initialized mesh handle.           *
  62. *                                                                    *
  63. * Comment      : This function is an implementation of Nikola        *
  64. *                Smolenski his GalaxyCreator algorithm.              *
  65. *                                                                    *
  66. \********************************************************************/
  67. void galaxy (ULONG mesh) {
  68.   TOCLVertex v,v2;
  69.   TOCLColor color;
  70.   ULONG j,angle,c[25];
  71.   FLOAT Ri,Si,R1,R,i,h;
  72.  
  73.   srand(rand());
  74.  
  75.   for(j=0;j<5;j++) {
  76.     MWLMeshMaterialAdd(mesh,&c[j]);
  77.     color.r=255-j*10,color.g=255-j*10,color.b=255-j*10;
  78.     MWLMeshMaterialDiffuseColorSet(mesh,c[j],&color);
  79.   }
  80.  
  81.   for(j=5;j<25;j++) {
  82.     MWLMeshMaterialAdd(mesh,&c[j]);
  83.     color.r=255-j*10,color.g=255-j*10,color.b=255;
  84.     MWLMeshMaterialDiffuseColorSet(mesh,c[j],&color);
  85.   }
  86.  
  87.   angle=5;
  88.   Ri=0;
  89.   Si=5;
  90.   R1=10;
  91.   h=0;
  92.   for(i=0.2;i<=angle;i+=0.2) {
  93.     Ri+=Si;
  94.     R=random(6)+R1;
  95.     v.x=cos(i)*Ri;v.y=sin(i)*Ri,v.z=0;
  96.     for(j=1;j<=R;j++) {
  97.       v2.x=v.x-random(5);v2.y=v.y-random(5);
  98.       v2.z=random(cos(h)*20);h+=PI/50;
  99.       particleadd(mesh,c[(ULONG)(i/0.2)-1],2,v2);
  100.       v.x+=random(10);v.y+=random(10);
  101.     }
  102.   }
  103.  
  104.   angle=5;
  105.   Ri=0;
  106.   Si=5;
  107.   R1=10;
  108.   h=0;
  109.   for(i=0.2;i<=angle;i+=0.2) {
  110.     Ri+=Si;
  111.     R=random(6)+R1;
  112.     v.x=-cos(i)*Ri;v.y=-sin(i)*Ri,v.z=0;
  113.     for(j=1;j<=R;j++) {
  114.       v2.x=v.x-random(5);v2.y=v.y-random(5);
  115.       v2.z=random(cos(h)*20);h+=PI/50;
  116.       particleadd(mesh,c[(ULONG)(i/0.2)-1],2,v2);
  117.       v.x+=random(10);v.y+=random(10);
  118.     }
  119.   }
  120. }
  121.  
  122. /************************* End of file ******************************/
  123.